package com.chb.demo.service;

import com.chb.demo.dao.OrderDao;
import com.chb.demo.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class OrderService {
    @Autowired
    OrderDao orderDao;


    public Map<String, Object> makeDeal(Integer pid, String account) {
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat dateformat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        String time=dateformat.format(new Date());

        boolean success = false;
        try {
            //orderDao.savemyorder(pid, account);
            orderDao.save(new Order().setPid(pid).setAccount(account).setOtime(time));
            success = true;
        }catch (Exception e){
            System.out.println(pid+"  "+account);
            System.out.println("有异常");
        }
        map.put("success",success);
        return map;

    }
}
